package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.common.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.OpenFeignPaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName : com.atguigu.springcloud.controller.OrderController
 * @Description : 类描述
 * Created by cyd on 2021-10-05 20:37:04
 */
@RestController
@Slf4j
public class OrderController {

    // 注入openFeign接口的实现类，由框架为我们实现
    @Resource
    OpenFeignPaymentService paymentService;

    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        log.info("id:{}", id.toString());
        // 远程调用，甚至无法察觉是在发http请求
        CommonResult<Payment> paymentResult = paymentService.getPayment(id);
        log.info("payment:{}", paymentResult.getData());
        return paymentResult;
    }

    // 超时控制测试
    @GetMapping("/consumer/payment/feignTimeout")
    public String feignTimeout() {
        return paymentService.feignTimeout();
    }

}
